package com.ibeetl.bbs;

import java.io.IOException;
import java.sql.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;


import com.ibeetl.bbs.lucene.LuceneService;
import com.ibeetl.bbs.lucene.dto.ik.IKAnalyzer5x;
import com.ibeetl.bbs.lucene.dto.jieba.JiebaAnalyzer;

public class SearchTest {



	private static final String URL="jdbc:mysql://127.0.0.1:3306/bbs?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true";
     private static final String NAME="root";
    private static final String PASSWORD="1qaz2wsx";



	public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		//2.获得数据库的连接
		Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD);


		while(true){


			if(mv(conn)){
				break;

			}

		}







		}

	private static boolean mv(Connection connection) throws SQLException {

		PreparedStatement statement = null;
		ResultSet rs = null;

		String sql = "select * from temp";


		statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

		rs  = statement.executeQuery();

		int count=0;

		Map<String,String> contents = new HashMap<>();

		while (rs.next()){

			String title = rs.getString("title");
			String content = rs.getString("content");
			contents.put(title,content);
		}
		rs.close();
		statement.close();

			int begin  =190;
		for (Map.Entry<String, String> stringStringEntry : contents.entrySet()) {
			String title = stringStringEntry.getKey();
			String content = stringStringEntry.getValue();
			Statement st = connection.createStatement();
			st.executeUpdate("insert into bbs_topic (content) values('"+title+"')");
			st.close();

			PreparedStatement ps = connection.prepareStatement("insert into bbs_post (topic_id,content) values(?,?)");
			ps.setInt(1,begin);
			ps.setString(2,content);
			ps.executeUpdate();
			ps.close();
			begin++;
		}












		return  true;
	}


}
